using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace EntLibContrib.ExceptionHandling.Configuration
{
    public class ErrorCodeEntryData : NamedConfigurationElement
    {
        private static AssemblyQualifiedTypeNameConverter typeConverter = new AssemblyQualifiedTypeNameConverter();

        public ErrorCodeEntryData() 
        {
        }

        public ErrorCodeEntryData(string name)
            : base(name)
        {
        }

        private const string ErrorCodePropertyName = "errorCode";
        [ConfigurationProperty(ErrorCodePropertyName)]
        public int ErrorCode
        {
            get { return (int)this[ErrorCodePropertyName]; }
            set { this[ErrorCodePropertyName] = value; }
        }

        private const string WrapExceptionTypeNamePropertyName = "wrapExceptionTypeName";
        [ConfigurationProperty(WrapExceptionTypeNamePropertyName)]
        public string WrapExceptionTypeName
        {
            get { return (string)this[WrapExceptionTypeNamePropertyName]; }
            set { this[WrapExceptionTypeNamePropertyName] = value; }
        }

        private const string ExceptionMessagePropertyName = "exceptionMessage";
        [ConfigurationProperty(ExceptionMessagePropertyName)]
        public string ExceptionMessage
        {
            get { return (string)this[ExceptionMessagePropertyName]; }
            set { this[ExceptionMessagePropertyName] = value; }
        }

        /// <summary>
        /// Gets or sets the type of the replacement exception.
        /// </summary>
        public Type WrapExceptionType
        {
            get { return (Type)typeConverter.ConvertFrom(WrapExceptionTypeName); }
            set { WrapExceptionTypeName = typeConverter.ConvertToString(value); }
        }
    }
}
